<script type="text/javascript">
var errors=false;
function check(input)
{
		var div='#'+input+'Info';
		var ele = '#'+input;
		ele=$(ele);
		if (ele.val().length<2)
		{
			if ($(div).length<=0)  //questo metodo controlla l'esistenza del div
			{
				$('#ricerca').append('<div id="'+input+'Info" class="info"></div>');
				var typeInfo = $('#'+input+'Info');
				var pos = ele.offset();
				typeInfo.css({
					top: pos.top-3,
				left: pos.left+ele.width()+15
				});
				typeInfo.removeClass('correct').addClass('error').html('&larr; Inserire almeno 2 caratteri').fadeIn();
				ele.removeClass('normal').addClass('wrong');				
			}
			
		}
		else
		{		
		  var typeInfo = $('#'+input+'Info');
			var pos = ele.offset();
			typeInfo.css({
			top: pos.top-3,
			left: pos.left+ele.width()+15
			});
		if( ele.val().length<3) {
			  typeInfo.removeClass('correct').addClass('error').html('&larr; Inserire almeno 2 caratteri').show();
				ele.removeClass('normal').addClass('wrong');	
		} else{
				typeInfo.removeClass('error').addClass('correct').html('&radic;').show();
				ele.removeClass('wrong').addClass('normal');
				errors=true;
		} 
		}
}	
	
function sostituisciSpazio(stringa)
{
	var parts = stringa.split(' '),
            len = parts.length,i;
			var ind='';
        	for(i = 0; i < len-1; i += 1) {
            	ind += parts[i]+'%20';
        	} 
		    ind+=parts[len-1];
			return ind;
}


$('#button').click(function (){
		errors=false;
		check('nickname');
		check('password');
		check('nome');
		check('cognome');
		var id=$('select option:selected').val();
		if(errors) {
			var jrole = "utenti/visualizza.php";
			var data="nickname='"+$('#nickname').val()+"'&password='"+$('#password').val();
			data=data+"'&nome='"+$('#nome').val();
			data=data+"'&cognome='"+$('#cognome').val();
			data=data+"'&idgrado="+id+"&up=<?php echo $_GET['id']; ?>";
			jrole=jrole+"?"+data;
			$('#ricerca').fadeOut(1000,function(){$('#ricerca').load(jrole,'',$('#ricerca').fadeIn(1000))});
			return false;
		}
	return false;
});


// ======================================================  //
</script>

<?php require_once('../Connections/mlu.php'); 


$query_Recordset1 = "SELECT * FROM gradi";
$Recordset1 = mysql_query($query_Recordset1, $mlu) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$query_Recordset2 = "SELECT * FROM operatori WHERE idop =". $_GET['id'];
$Recordset2 = mysql_query($query_Recordset2, $mlu) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Idop:</td>
      <td><?php echo $row_Recordset2['idop']; ?></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Nickname:</td>
      <td><input type="text" name="nickname" value="<?php echo $row_Recordset2['nickname']; ?>" size="32" id="nickname"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Password:</td>
      <td><input type="text" name="password" value="<?php echo $row_Recordset2['password']; ?>" size="32" id="password"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Nome:</td>
      <td><input type="text" name="nome" value="<?php echo $row_Recordset2['nome']; ?>" size="32" id="nome"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Cognome:</td>
      <td><input type="text" name="cognome" value="<?php echo $row_Recordset2['cognome']; ?>" size="32" id="cognome"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Idgrado:</td>
      <td><select name="idgrado">
        <?php 
do {  
?>
        <option value="<?php echo $row_Recordset1['idgrado']?>" <?php if (!(strcmp($row_Recordset1['idgrado'], $row_Recordset2['idgrado']))) {echo "SELECTED";} ?>><?php echo $row_Recordset1['typegrado']?></option>
        <?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
?>
      </select></td>
    </tr>
    <tr> </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><button id="button">Aggiorna</button></td>
    </tr>
  </table>